<template>
	<!-- 添加车辆 -->
	<view class="addCar">
		<u-navbar title="修改发单信息" title-color="#333" back-icon-color="#333"></u-navbar>
		<view class="addCar-bottom">
			<view class="zx-addres">
				<!-- <view class="title u-line-2"><span class="zhuang-huo-dizhi">装</span><input class="addCar-input-one"
						type="text" placeholder="请输入装货地址" disabled="disabled" v-model="zxobj.zhdz" /></view> -->
				<view class="title u-line-2"><span class="xie-huo-dizhi">卸</span><input class="addCar-input-one"
						type="text" placeholder="请输入卸货地址" v-model="zxobj.xhdz" /></view>
			</view>
			<view class="addCar-content-box">
				<!--  -->
				<!-- <view class="">
					<text>地址</text>
				</view> -->

				<view class="cx-box">
					<u-radio-group v-model="cx" @change="radioGroupChange">
						<text class="addCar-phone">车型：</text>
						<u-radio @change="radioChange" v-for="(item, index) in list1" :key="index" :name="item.name"
							:disabled="item.disabled" :checked="item.checked">
							{{item.name}}
						</u-radio>
					</u-radio-group>
					</checkbox-group>
				</view>

				<view class="addCar-carName-phone">
					<text class="addCar-phone">厂家：</text>
					<!-- <picker class="addCar-input-one" @change="bindPickerChange" :value="msgobj.wlcj"
						:range="cjArray" range-key="SETTB99CA00" >
						<i class="addCar-phone-placeholder" v-if="msgobj.wlcj<0&&huixian ==''">请选择厂家</i>
						<view v-if="huixian =='hx'" class="uni-input">{{huixianMasgcj}}</view>
						<view v-if="msgobj.wlcj>=0&&huixian =='1'" class="uni-input">{{cjArray[msgobj.wlcj].SETTB99CA00}}</view>
						
					</picker> -->
					<input class="addCar-input-one" type="text" placeholder="请选择厂家" disabled="disabled" v-model="huixianMasgcj"
						 />
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">物料类型：</text>
					<!-- <picker class="addCar-input-one" @change="bindPickerWlChange" :value="msgobj.wllx" :range="wlArray"
						range-key="settb109CA00">
						<i class="addCar-phone-placeholder" v-if="msgobj.wllx<0&&huixian ==''">请选择物料</i>
						<view v-if="huixian =='hx'" class="uni-input">{{huixianMasgwl}}</view>
						<view v-else class="uni-input">{{wlArray[msgobj.wllx].settb109CA00}}</view>
					</picker> -->
					<input class="addCar-input-one" type="text" placeholder="请输入物料名称" disabled="disabled" v-model="huixianMasgwl"
						 />
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">车数：</text>
					<input class="addCar-input-one" type="text" placeholder="请输入车数" disabled="disabled" v-model="msgobj.cs"
						 />
				</view>
				<view class="addCar-carName-phone">
					<text class="addCar-phone">运费：</text>
					<input class="addCar-input-one" type="number" placeholder="请输入运费" disabled="disabled" v-model="msgobj.yf"
						 />
					<text>每吨</text>
				</view>
				<!-- 	<view class="add-phone-main">


					<view class="addCar-carName-phone" v-for="(item, index) in list">
						<text class="addCar-phone">联系方式：</text>
						<input class="addCar-input-one" type="number" @input="phoneIptInput" placeholder="请输入联系方式"
							v-model="item.phone" maxlength="11" />
						<span style="color: red;" v-if="list.length>=2" @click="delItem(item)">删除</span>

					</view>
					<view class="add-phone" @click="addItem">添加</view>
				</view> -->
				<!-- <view class="addCar-carName-phone">
					<text class="addCar-phone">皮重：</text>
					<input class="addCar-input-one" @input="tareIptInput" placeholder="请输入皮重" type="number"
						v-model="tareIpt" />
					<text class="addCar-dun">吨</text>
				</view> -->
			</view>
			<!--  -->
			<view class="addCar-reset-determine">
				<!-- <view class="add-phone" @click="addItem">新增电话</view> -->
				<!-- <view class="addCar-reset" @click="reset">重置</view> -->
				<view class="addCar-determine" @click="determine">确定</view>
			</view>
		</view>
		<u-modal v-model="addCarLoginShow" content="请确认是否修改该信息" :show-cancel-button="true" @confirm="addCarConfirm">
		</u-modal>
		<u-keyboard ref="uKeyboard" mode="car" @change="carValChange" @backspace="carBackspace" v-model="carshow"
			:mask="false"></u-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userinfo: JSON.parse(uni.getStorageSync('userinfo')),
				componeryArr: [],
				addressNew: null,
				Index: 0,
				diasabledInput: true, //可读不可写
				carNumberIpt: '', //车牌号
				nameIpt: '', //车主姓名
				phoneIpt: '', //联系方式
				tareIpt: '', //联系方式
				addCarLoginShow: false,
				carshow: false,
				carType: '',
				typeid: '',
				zxobj: {
					zhdz: '',
					xhdz: ''
				},
				msgobj: {
					wllx: -1,
					wlcj: -1,
					wlcjName: '',
					wlcjId: '',
					wllxName: '',
					wllxId: '',
					wllxDj:'',
					cs: '',
					yf: ''
				},
				cjArray: [],
				wlArray: [],
				obj:"",
				page: 1,
				huixian:'',
				huixianMasgcj:'',
				huixianMasgwl:'',
				list1: [{
						name: '13米',
						checked: true,
						disabled: true
					},
					{
						name: '7米6',
						checked: false,
						disabled: true
					},
					{
						name: '9米6',
						checked: false,
						disabled: true
					}

				],
				ORMTB460ID:'',
				cx: '13米',
				list: [{
					phone: ''
				}]
			}
		},
		onLoad(option) {
			console.log(JSON.parse(decodeURIComponent(option.itemMasg)))
			var masg = JSON.parse(decodeURIComponent(option.itemMasg))
			this.ORMTB460ID = masg.ORMTB460ID
			this.zxobj.zhdz = masg.ORMTB460CA00
			this.zxobj.xhdz = masg.ORMTB460CA01
			this.msgobj.cs = masg.ORMTB460CA08
			this.msgobj.yf = masg.ORMTB460CA09
			this.cx = masg.ORMTB460CA02
			this.huixianMasgcj = masg.ORMTB460CA04
			this.huixianMasgwl = masg.ORMTB460CA06
			console.log(masg.ORMTB460CA02)
			
			this.getOrderList()
		},
		onShow() {
			
		},

		mounted() {
		
		},

		methods: {
			bindPickerChange: function(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.msgobj.wlcj = e.detail.value
				console.log(this.msgobj.wlcj)
				this.msgobj.wlcjName = this.cjArray[this.msgobj.wlcj].SETTB99CA00
				this.msgobj.wlcjId = this.cjArray[this.msgobj.wlcj].SETTB99ID
				this.huixian = '1'
				console.log(this.msgobj.wlcjName)
				this.queryGwcList()
				
			},
			bindPickerWlChange(e) {
				this.msgobj.wllx = e.detail.value
				console.log('物料',this.msgobj.wllx)
				this.msgobj.wllxName = this.wlArray[this.msgobj.wllx].settb109CA00
				this.msgobj.wllxId = this.wlArray[this.msgobj.wllx].settb109ID
				this.msgobj.wllxDj = this.wlArray[this.msgobj.wllx].settb109CA01
					console.log(this.wlArray[this.msgobj.wllx].settb109ID)
				
			},

			// 选中某个单选框时，由radio时触发
			radioChange(e) {
				// console.log(e);
			},
			radioGroupChange(e) {
				// console.log(e);
			},


			// 企业列表
			getOrderList() {
				uni.showLoading({
					title: '请求中...',
					mask: true
				});
				uni.request({
					url: this.baseUrl + '/set/settb99/selectPageList',
					method: 'POST',
					dataType: 'json',
					data: {
						SETTB403CA00: this.userinfo.PERTB005ID,
						ORMTB410ID: this.userinfo.ORMTB410ID,
						ORMTB400ID: this.userinfo.ORMTB400ID, //一级客户ID
						SETTB99CA00: '', //二级企业名称
						SETTB100CA04: this.cityCode, //市代码
						page: this.page,
						limit: 100,
					},
					success: (res) => {
						uni.hideLoading();
						if (res.data.code == 200) {
							if (!res.data.data || res.data.data == null) {
								this.cjArray = []
								this.page = 1
								return
							}
							var data = res.data.data || []
							console.log(data)
							this.cjArray = data
						} else {
							this.cjArray = []
							this.page = 1
							uni.showToast({
								title: res.data.message,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: '服务器连接超时',
							type: 'default',
							icon: false
						})
					}
				});
			},
			// 物料列表
			queryGwcList() {
				uni.showLoading({
					title: '加载中...',
					mask: true
				});
				// this.materList=[]
				var ORMTB410ID = ''
				if (this.userinfo.sign == "CUS-2" || this.userinfo.sign == 'CUS-3') {
					ORMTB410ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb440/selectAllSettb109',
					method: 'POST',
					dataType: 'json',
					data: {
						SETTB99ID: this.msgobj.wlcjId, //二级企业代码
						ORMTB410ID: ORMTB410ID,
						sign: this.userinfo.sign,
					},
					success: (res) => {
						console.log(res);
						uni.hideLoading();
						if (res.data.code == 200) {
							// this.materList=res.data.data||[]
							this.wlArray = res.data.data || []
							console.log(this.wlArray)

						} else {
							uni.showToast({
								title: res.data.success,
								type: 'default',
								icon: false
							})
						}
					},
					fail: (res) => {
						uni.hideLoading();
						uni.showToast({
							title: res.errMsg,
							type: 'default',
							icon: false
						})
					}
				});
			},


			addItem() {
				if (this.list.length == 3) {
					uni.showToast({
						title: '最多三个',
						icon: 'none'
					})
					return false
				}
				// let add = {
				// 	id: parseInt(this.id) + 1
				// }
				this.list.push({
					phone: ''
				})
				// this.id = parseInt(this.id) + 1
				// this.phoneIpt += parseInt(this.id) + 1
				console.log(this.list)
			},
			delItem(item) {
				if (this.list.length == 1) {
					uni.showToast({
						title: '不能删除第1个',
						icon: 'none'
					})
					return false;
				}
				this.list = this.list.filter((i) => {
					return i != item
				})
			},
			carValChange(val) {
				// 将每次按键的值拼接到carNumberIpt变量中，注意+=写法
				this.carNumberIpt += val;
			},
			carBackspace() {
				// 删除carNumberIpt的最后一个字符
				if (this.carNumberIpt.length) this.carNumberIpt = this.carNumberIpt.substr(0, this.carNumberIpt.length -
					1);
			},
			boardClick() {
				this.carshow = true
			},
			tareIptInput() { //限制验证码长度
				if (this.tareIpt.length > 6) {
					this.tareIpt = this.tareIpt.slice(0, 6)
				}
			},
			phoneIptInput() {
				if (this.phoneIpt.length > 11) {
					this.phoneIpt = this.phoneIpt.slice(0, 11)
				}
			},
			// 确定
			determine() {
				//车牌号
				// var regC =
				// 	/^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领])|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][0-9]{2}([0-9]|[A-Z]){5}))$/;
				// var regP = /^1[3-9][0-9]{9}$/;

				// for (let index = 0; index < this.list.length; index++) {
				// 	if (this.list[index].phone == '') {
				// 		return uni.showToast({
				// 			title: '请输入手机号',
				// 			duration: 5000,
				// 			icon: 'none',
				// 		});
				// 	}
				// 	if (this.list[index].phone != '') {
				// 		if (!regP.test(this.list[index].phone)) return uni.showToast({
				// 			title: '手机号格式不正确，请检查',
				// 			duration: 5000,
				// 			icon: 'none',
				// 		});
				// 	}
				// }
				// if(this.phoneIpt ==''){
				// 	return uni.showToast({
				// 		title: '请输入手机号',
				// 		duration: 5000,
				// 		icon: 'none',
				// 	});
				// }

				if (this.zxobj.xhdz == '') {
					return uni.showToast({
						title: '请输入卸货地址',
						duration: 5000,
						icon: 'none',
					});
				}


				this.addCarLoginShow = true

			},
			addCarConfirm() {
				if (this.userinfo.sign == 'CUS-1') {
					var ORMTB400ID = this.userinfo.ORMTB400ID
				} else if (this.userinfo.sign == 'CUS-2' || this.userinfo.sign == 'CUS-3') {
					var ORMTB400ID = this.userinfo.ORMTB410ID
				}
				uni.request({
					url: this.baseUrl + '/orm/ormtb460/update',
					method: 'POST',
					dataType: 'json',
					data: {
						ORMTB460CA01: this.zxobj.xhdz,//卸货地址
						
						ORMTB460ID:this.ORMTB460ID,
						// sign: this.userinfo.sign,
						// ORMTB410ID: ORMTB400ID,
					},
					success: (res) => {
						console.log(res);
						if (res.data.code == 200) {
							uni.showToast({
								title: '修改成功',
								duration: 5000,
								icon: 'none',
							});
							uni.navigateBack()
						} else {
							uni.showToast({
								title: res.data.message,
								duration: 5000,
								icon: 'none',
							});
						}
					},
					fail: (res) => {
						uni.showToast({
							title: res.data.message,
							duration: 5000,
							icon: 'none',
						});
					}
				});
			},
			// 重置
			reset() {
				this.carNumberIpt = '' //车牌号
				this.nameIpt = '' //车主姓名
				this.phoneIpt = '' //联系方式
				this.tareIpt = ''
			},
		}
	}
</script>

<style scoped>
	.addCar input {
		border: 0;
	}

	.addCar {
		width: 100%;
		min-height: 100vh;
		background-color: rgba(242, 242, 242, 1);
		overflow: hidden;
	}

	/* 列表 */

	/* 内容 */
	.addCar-content-box {
		/* width: 100%; */
		background: rgba(255, 255, 255, 1);
		padding: 10rpx 24rpx;
		margin: 20rpx;
		border-radius: 20rpx;
		box-shadow: 4rpx 4rpx 20rpx #e5e5e5;
	}

	.addCar-carName-phone {
		/* border-bottom: 2rpx solid rgba(230, 230, 230, 1); */
		padding: 18rpx 0;
	}

	.addCar-input-one {
		width: 310rpx !important;
		display: inline-block;
		margin-bottom: 0 !important;
		padding: 0 !important;
		height: 44rpx !important;
		vertical-align: middle;
		/* margin-left: 0.1rem; */
		color: rgba(51, 51, 51, 1);
		font-size: 28rpx;
		text-align: center;
	}

	.addCar-phone {
		width: 180rpx;
		display: inline-block;
		font-size: 30rpx;
		color: rgba(102, 102, 102, 1);
		vertical-align: middle;
		/* background: #000000; */
	}

	.addCar-phone-placeholder {
		font-size: 30rpx;
		color: rgba(102, 102, 102, .5);
	}

	.addCar-dun {
		color: rgba(51, 51, 51, 1);
		font-size: 30rpx;
	}

	/* 按钮 */
	.addCar-reset-determine {
		margin-top: 167rpx;
		display: flex;
		justify-content: center;
	}



	.addCar-reset-determine>view {
		width: 80%;
		text-align: center;
		line-height: 100rpx;
		color: rgba(255, 255, 255, 1);
		font-size: 32rpx;
		border-radius: 20rpx;
	}

	.addCar-reset {
		width: 159rpx;
		background: rgba(234, 197, 15, 1);
		text-align: center;
		/* margin-left: 170rpx; */
		margin: 0 20rpx;
	}

	.addCar-determine {
		background: rgba(0, 161, 244, 1);
		/* margin-left: 60rpx; */
	}

	.add-phone-main {
		position: relative;
	}

	.add-phone {
		position: absolute;
		top: 20rpx;
		right: 0;
		/* font-size: 50rpx; */
		color: rgba(0, 255, 127, 1);
		/* background: rgba(0, 255, 127, 1); */

	}

	.addCar-phone-car {
		display: inline-block;
		width: 310rpx;
		height: 44rpx;
		line-height: 44rpx;
		/* border: 1px solid rgba(0, 0, 0, .2); */
		/* border-radius: 3px; */
		text-align: center;
		vertical-align: middle;
		font-size: 30rpx;
	}

	input::placeholder {
		color: rgba(102, 102, 102, .5);
	}

	.item-box {
		display: flex;
	}

	.zhuang-huo-dizhi {
		background-color: #303133;
		color: #fff;
		border-radius: 50%;
		width: 50rpx;
		height: 50rpx;
		display: inline-block;
		font-size: 32rpx;
		text-align: center;
		margin-right: 10rpx;
		margin-bottom: 20rpx;
	}

	.xie-huo-dizhi {
		background-color: #2979ff;
		color: #fff;
		border-radius: 50%;
		width: 50rpx;
		height: 50rpx;
		display: inline-block;
		font-size: 32rpx;
		text-align: center;
		margin-right: 10rpx;
	}

	.zx-addres {
		background: rgba(255, 255, 255, 1);

		border-radius: 20rpx;
		box-shadow: 4rpx 4rpx 20rpx #e5e5e5;
		padding: 20rpx 24rpx;
		padding-bottom: 30rpx;
		/* border-bottom: 2rpx solid rgba(230, 230, 230, 1); */
		margin: 20rpx;

	}

	.cx-box {
		padding: 18rpx 0;
	}
</style>
